<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 输入：['a','b','c','d','e','f','a','b','c'] 'a'
      // 输出：[0, 6]
      let arr = ["a", "b", "c", "d", "e", "f", "a", "b", "c"];
      let newArr = []; 
      let item = "a";
      function array(arr, item) {
        arr.forEach((item2, index) => {
          if (item2 == item) {
            newArr.push(index);
          }
        });
        return newArr;
      }
      array(arr, item);
      console.log(newArr);
      // 结果：[0, 6]
    </script>
  </body>
</html>
